package com.wxl.common.wiget

import android.content.Context
import android.util.AttributeSet
import android.view.KeyEvent
import androidx.appcompat.widget.AppCompatAutoCompleteTextView

open class SkinKeyEventEditorText : AppCompatAutoCompleteTextView {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )


    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        if(mOnKeyDownEventCallback != null) {
            val onKeyDownEvent = mOnKeyDownEventCallback!!.onKeyDownEvent(keyCode, event)
            if(!onKeyDownEvent){
               return super.onKeyDown(keyCode, event)
            }
            return true
        }
        return super.onKeyDown(keyCode, event)
    }

    private var mOnKeyDownEventCallback:OnKeyDownEventCallback?=null
    fun setOnKeyDownEventCallback(mOnKeyDownEventCallback:OnKeyDownEventCallback){
        this.mOnKeyDownEventCallback = mOnKeyDownEventCallback
    }

    companion object {
        interface OnKeyDownEventCallback{
            fun onKeyDownEvent(keyCode: Int, event: KeyEvent?):Boolean
        }

    }
}